package com.ruoyi.project.lesson.order.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.lesson.order.domain.LessonOrder;
import com.ruoyi.project.lesson.order.service.ILessonOrderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 课程订单Controller
 * 
 * @author shixiangwen
 * @date 2020-12-07
 */
@Controller
@RequestMapping("/lesson/order")
public class LessonOrderController extends BaseController
{
    private String prefix = "lesson/order";

    @Autowired
    private ILessonOrderService lessonOrderService;

    @RequiresPermissions("lesson:order:view")
    @GetMapping()
    public String order()
    {
        return prefix + "/order";
    }

    /**
     * 查询课程订单列表
     */
    @RequiresPermissions("lesson:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LessonOrder lessonOrder)
    {
        startPage();
        List<LessonOrder> list = lessonOrderService.selectLessonOrderList(lessonOrder);
        return getDataTable(list);
    }

    /**
     * 导出课程订单列表
     */
    @RequiresPermissions("lesson:order:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LessonOrder lessonOrder)
    {
        List<LessonOrder> list = lessonOrderService.selectLessonOrderList(lessonOrder);
        ExcelUtil<LessonOrder> util = new ExcelUtil<LessonOrder>(LessonOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 新增课程订单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存课程订单
     */
    @RequiresPermissions("lesson:order:add")
    @Log(title = "课程订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LessonOrder lessonOrder)
    {
        return toAjax(lessonOrderService.insertLessonOrder(lessonOrder));
    }

    /**
     * 修改课程订单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LessonOrder lessonOrder = lessonOrderService.selectLessonOrderById(id);
        mmap.put("lessonOrder", lessonOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程订单
     */
    @RequiresPermissions("lesson:order:edit")
    @Log(title = "课程订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LessonOrder lessonOrder)
    {
        return toAjax(lessonOrderService.updateLessonOrder(lessonOrder));
    }

    /**
     * 删除课程订单
     */
    @RequiresPermissions("lesson:order:remove")
    @Log(title = "课程订单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lessonOrderService.deleteLessonOrderByIds(ids));
    }
}
